import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import NProgress from "nprogress";
import "nprogress/nprogress.css";

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "Home",
    component: () => import("./../views/home/home.vue"),
  },
  {
    path: "/cart",
    name: "Cart",
    component: () => import("./../views/cart/cart.vue"),
  },
  {
    path: "/my",
    name: "My",
    component: () => import("./../views/my/my.vue"),
  },
  {
    path: "/fenlei",
    name: "Fenlei",
    component: () => import("./../views/fenlei/index.vue"),
  },
];

const router = createRouter({
  history: createWebHashHistory(), // history 模式则使用 createWebHistory()
  routes,
});

router.beforeEach(async (_to, _from, next) => {
  NProgress.start();
  next();
});

router.afterEach((_to) => {
  NProgress.done();
});

export default router;
